	<link rel="stylesheet" type="text/css" href="css/fitem.css">
	<script type="text/javascript">
            $(function(){
               $('#dgQuotation').datagrid({
                   view:detailview,
                   detailFormatter:function(index,row){
                       return '<div id="ddv-quotation-'+index+'" style="padding:10px"></div>'
                   },
                   onExpandRow:function(index,row){
                       $('#ddv-quotation-'+index).panel({
                           border:false,
                           cache:false,
                           href:'pages/quotation/quotation_getdetail.php?id='+row.idQuotation,
                           onLoad:function(){
                               $('#dgQuotation').datagrid('fixDetailRowHeight',index);
                           }
                       });
                       $('#dgQuotation').datagrid('fixDetailRowHeight',index);
                   }
               }); 
            });

            var url;
            var urlstep2;
            var newtemp;
            var edittemp;
            var removetemp;
            var canceltemp;
            function newquotation(){
                $('#dlgQuotation_step1').dialog('open').dialog('setTitle','New Quotation Step 1');
                $('#fmQuotation_step1').form('clear');
                url = 'pages/quotation/quotation_new.php';
                newtemp='temp=x';
                edittemp='temp=x';
                removetemp='temp=x';
                canceltemp='cancel=next2';
            }
            
            function editquotation(){
                var row = $('#dgQuotation').datagrid('getSelected');
                if (row){
                    $('#dlgQuotation_step2').dialog('open').dialog('setTitle','Edit Quotation');	// open the dialog step2
                    $('#dgQuotation_step2').datagrid({url:'pages/quotation/quotation_getdata.php?step=2&id='+row.idQuotation})
                    url = 'pages/quotation/quotation_update.php?idQuotation='+row.idQuotation;
                    newtemp='temp=editx&idQuotation='+row.idQuotation;
                    edittemp='temp=editx&idQuotation='+row.idQuotation;
                    removetemp='temp=editx&idQuotation='+row.idQuotation;
                    canceltemp='cancel=nextedit2&idquotation='+row.idQuotation;
                }else{
                    $.messager.alert('Warning','Pilih dulu salah satu Quotation.','warning');
                }
            }
            
            function savequotation(){
                $.ajax({
                    url: url,
                    data: "step=finish",
                    cache: false,
                    success: function(result){
                        var result = eval('('+result+')');
                        if (result.success){
                            $('#dlgQuotation_step2').dialog('close');
                            $('#dgQuotation').datagrid('reload');
                        }else{
                            $.messager.show({
                                title:'Error',
                                msg:result.msg
                            });
                        }
                    }
                });                
            }
            function removequotation(){
                var row = $('#dgQuotation').datagrid('getSelected');
                if (row){
                    $.messager.confirm('Confirm','Are you sure you want to remove this quotation?',function(r){
                        if (r){
                            $.post('pages/quotation/quotation_remove.php',{id:row.id},function(result){
                                if (result.success){
                                    $('#dgQuotation').datagrid('reload');	// reload the user data
                                } else {
                                    $.messager.show({	// show error message
                                        title: 'Error',
                                        msg: result.msg
                                    });
                                }
                            },'json');
                        }
                    });
                }
            }
            
            function printquotation(){
                var row = $('#dgQuotation').datagrid('getSelected');
                if (row){
                    $.messager.confirm('Confirm','Anda akan mencetak quotation <br>'+row.noQuotation+'<br>lanjutkan?',function(r){
                        if (r){
//                            $.post('pages/quotation/quotation_print.php',{id:row.idQuotation}
//                            ,function(result){
//                                if (result.success){
//                                    $('#dgQuotation').datagrid('reload');	// reload the user data
//                                } else {
//                                    $.messager.show({	// show error message
//                                        title: 'Error',
//                                        msg: result.msg
//                                    });
//                                }
//                            },'json'
//                            );
                            window.open ('pages/quotation/quotation_print.php?id='+row.idQuotation,"Print Quotation");
                        }
                    });
                } else {
                    $.messager.alert('Error','Silahkan pilih salah satu Quotation terlebih dulu','warning');
                }
            }
            
            function next1(){
                $('#fmQuotation_step1').form('submit',{
                    url: 'pages/quotation/quotation_next.php?step=1',
                    onSubmit: function(){
                        return $(this).form('validate');
                    },
                    success: function(result){
                        var result = eval('('+result+')');
                        if (result.success){
                            $('#dlgQuotation_step1').dialog('close');	// close the dialog step1
                            $('#dlgQuotation_step2').dialog('open').dialog('setTitle','Quotation step 2');	// open the dialog step2
                            $('#dgQuotation_step2').datagrid({url:'pages/quotation/quotation_getdata.php?step=2&id='+result.msg})
                        } else {
                            $.messager.show({
                                title: 'Error',
                                msg: result.msg
                           });
                        }
                    }
                });
            }
            
            function cancel_next2(){
                $.ajax({
                    url: "pages/quotation/quotation_next.php?"+canceltemp,
                    data: "",
                    cache: false,
                    success: function(msg){
                        var hasil = eval('('+msg+')');
                        //jika data sukses diambil dari server kita tampilkan
                        if (hasil.success){
                            $('#dlgQuotation_step2').dialog('close');
                        }else{
                            $.messager.show({
                                title:'Error',
                                msg:hasil.msg
                            });
                        }
                    }
                });
            }
            function step2_addItem(){
                $('#dlgQuotation_step2_1').dialog('open').dialog('setTitle','Tambah Barang');
                $('#fmQuotation_step2_1').form('clear');
                $('#idBarang').combogrid({
                    idField:'idBarang',
                    textField:'namaBarang',
                    mode:'remote',
                    url:'pages/getCombogridData.php?field=barang',
                    columns:[[
                            {field:'namaBarang',title:'Nama Barang',width:300}
                    ]]
                });
                $('#buttonaddquotationtemp').linkbutton({text:'Tambah Barang'});
                urlstep2 = 'pages/quotation/quotation_new.php?'+newtemp;            
            }
            function step2_editItem(){
                var row = $('#dgQuotation_step2').datagrid('getSelected');
                if(row){
                    $('#fmQuotation_step2_1').form('clear');
                    $('#dlgQuotation_step2_1').dialog('open').dialog('setTitle','Edit Barang Quotation Step 2');
                    $('#idBarang').combogrid({
                        idField:'idBarang',
                        textField:'namaBarang',
                        mode:'remote',
                        url:'pages/getCombogridData.php?field=barang',
                        columns:[[
                                {field:'namaBarang',title:'Nama Barang',width:300}
                        ]]
                    });
                    $('#fmQuotation_step2_1').form('load',row);
                    urlstep2 = 'pages/quotation/quotation_update.php?'+edittemp+'&id='+row.idQuotation_item;
                }
                $('#buttonaddquotationtemp').linkbutton({text:'Edit Barang'});
            }
            function step2_removeItem(){
                var row = $('#dgQuotation_step2').datagrid('getSelected');
                if (row){
                    $.messager.confirm('Confirm','Anda yakin menghapus barang ini dari daftar?',function(r){
                        if (r){
                            $.post('pages/quotation/quotation_remove.php?'+removetemp,{id:row.idQuotation_item},function(result){
                                if (result.success){
                                    $('#dgQuotation_step2').datagrid('reload');	// reload the user data
                                } else {
                                    $.messager.show({	// show error message
                                        title: 'Error',
                                        msg: result.msg
                                    });
                                }
                            },'json');
                        }
                    });
                }
            }
            function addQuotationTemp(){
                $('#fmQuotation_step2_1').form('submit',{
                    url: urlstep2,
                    onSubmit: function(){
                        return $(this).form('validate');
                    },
                    success: function(result){
                        var result = eval('('+result+')');
                        if (result.success){
                            $('#dlgQuotation_step2_1').dialog('close');	// close the dialog
                            $('#dgQuotation_step2').datagrid('reload');	// reload the user data
                        } else {
                            $.messager.show({
                                title: 'Error',
                                msg: result.msg
                           });
                        }
                    }
                });
            }
            
            function openDftInq(){
                $('#dftInquiry').dialog('open');
                $('#tbldftInquiry').datagrid({url:'pages/inquiry/inquiry_getdata.php?task=QgetI'});
            }

            function pilihInq(){
                var row = $('#tbldftInquiry').datagrid('getSelected');
                if (row){
                    $('#fmQuotation_step1').form('load',row);
                }
                $('#dftInquiry').dialog('close');
            }

        </script>
        
<!--    table halaman utama daftar quotation-->
    <table id="dgQuotation" title="Daftar Quotation" class="easyui-datagrid" 
                    url="pages/quotation/quotation_getdata.php"
                    toolbar="#toolbarQuotation" pagination="true"
                    rownumbers="true" fitColumns="true" singleSelect="true">
            <thead>
                    <tr>
                            <th field="noQuotation" width="50">No. Quotation</th>
                            <th field="no_inquiry" width="50">No Inquiry</th>
                            <th field="statusQuotation" width="50">Status</th>
                            <th field="crtbyQuotation" width="50">Created By</th>
                            <th field="crtdateQuotation" width="50">Created Date</th>
                            <th field="chgbyQuotation" width="50">Changed by</th>
                            <th field="chgdateQuotation" width="50">Changed Date</th>
                    </tr>
            </thead>
    </table>
    <div id="toolbarQuotation">
            <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newquotation()">New</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editquotation()">Edit</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removequotation()">Remove</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-print" plain="true" onclick="printquotation()">Print</a>
    </div>

<!--dialog step 1 membuat quotation temporary baru-->
    <div id="dlgQuotation_step1" class="easyui-dialog" 
         style="width:700px;height:auto;padding:10px;" 
         buttons="#dlgQuotation_step1-button" closed="true" 
         modal="true" closable="false">
        <form id="fmQuotation_step1" class="fitem" method="post">
            <table width="100%">
                <tbody>
                    <tr>
                        <td width="13%">From Inquiry</td>
                        <td width="37%"><input id="no_inquiry" name="no_inquiry" class="easyui-validatebox" type="text" style="width:80%" required>
                            <a href="javascript:void(0)" onclick="openDftInq()"><img src="images/up.gif"></a></td>
                        <td width="13%"></td>
                        <td width="37%"></td>
                    </tr>
                    <tr>
                        <td>To</td>
                        <td><input type="text" style="width:80%" name="namaCustomer" id="namaCustomer" readonly></td>
                        <td>Short Text</td>
                        <td><input type="text" style="width:98%" name="text" id="text" readonly></td>
                    </tr>
                    <tr>
                        <td>Attn</td>
                        <td><input type="text" style="width:80%" name="attn" id="attn" readonly></td>
                        <td>Phone / Fax</td>
                        <td><input type="text" style="width:45%" name="telp" id="telp" readonly> / 
                            <input type="text" style="width:46%" name="fax" id="fax" readonly></td>
                    </tr>
                    <tr><td>Desc</td>
                        <td colspan="3"><textarea name="desc" id="desc" style="height:50px;width:420px" readonly>
                            </textarea></td>
                    </tr>
                </tbody>
            </table>
        </form>
        <div id="dlgQuotation_step1-button">
            <a href="#" class="easyui-linkbutton" onclick="next1()" iconCls="icon-ok" plain="true">Next</a>            
            <a href="#" class="easyui-linkbutton" onclick="javascript:$('#dlgQuotation_step1').dialog('close')" iconCls="icon-cancel" plain="true">Cancel</a>            
        </div>
    </div>
        
<!--dialog mencari daftar inquiry untuk step 1-->
    <div id="dftInquiry" class="easyui-dialog" title="Daftar Inquiry" 
         style="width:500px;height: auto;padding: 5px;" closed="true">
        <table id="tbldftInquiry" class="easyui-datagrid"
               rowNumbers="true"
               pagination="true"
               fitColumns="true"
               singleSelect="true"
               toolbar="#toolbarGetInq"
               >
            <thead>
                <tr>
                    <th field="no_inquiry" width="150">No. Inquiry</th>
                    <th field="text" width="100">Short Text</th>
                    <th field="namaCustomer" width="100">Nama Customer</th>
                    <th field="crtdate" width="80">Date</th>
                    <th field="status" width="50">Status</th>
                </tr>
            </thead>
        </table>
    </div>
    <div id="toolbarGetInq">
        <a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-ok" onclick="pilihInq()">Pilih</a>
    </div>

<!--dialog 2 untuk memasukkan item2 yg diinginkan ke quotation temporary-->
    <div id="dlgQuotation_step2" class="easyui-dialog" style="width:700px;height:auto;padding:10px;" 
         buttons="#dlgQuotation_step2-button" closed="true" modal="true" closable="false">
        <table id="dgQuotation_step2" class="easyui-datagrid"
               fitColumns="true"
               singleSelect="true"
               toolbar="#toolbar_dgQuotationStep2"
               >
            <thead>
                <tr>
                    <th field="namaBarang" width="100">Item</th>
                    <th field="qtyBarang" width="100">Qty</th>
                    <th field="priceItem" width="100">Price</th>
                </tr>
            </thead>
        </table>
        <div id="toolbar_dgQuotationStep2">
            <a href="#" class="easyui-linkbutton" onclick="step2_addItem()">Add</a>
            <a href="#" class="easyui-linkbutton" onclick="step2_editItem()">Edit</a>
            <a href="#" class="easyui-linkbutton" onclick="step2_removeItem()">Remove</a>
        </div>
        <div id="dlgQuotation_step2-button">
            <a href="#" class="easyui-linkbutton" onclick="savequotation()" plain="true" iconCls="icon-ok">Finish</a>            
            <a href="#" class="easyui-linkbutton" onclick="cancel_next2()" plain="true" iconCls="icon-cancel">Cancel</a>            
        </div>
    </div>

<!--dialog untuk step 2, menambahkan item ke quotation temporary-->
    <div id="dlgQuotation_step2_1" class="easyui-dialog" style="width:700px;height:auto;padding:10px;" 
         buttons="#dlgQuotation_step2_1-button" closed="true" modal="true">
        <form id="fmQuotation_step2_1" class="fitem" method="post">
            <table width="100%">
                <tbody>
                    <tr>
                        <td width="13%">Nama Barang</td>
                        <td colspan="3">
                            <select id="idBarang" name="idBarang" style="width:250px;"></select></td>
                    </tr>
                    <tr>
                        <td>Qty</td>
                        <td><input type="text" style="width:80%" name="qtyBarang" id="qtyBarang" required></td>
                        <td>Harga</td>
                        <td><input type="text" style="width:98%" name="priceItem" id="priceItem" required></td>
                    </tr>
                </tbody>
            </table>
        </form>
        <div id="dlgQuotation_step2_1-button">
            <a href="#" id="buttonaddquotationtemp" class="easyui-linkbutton" onclick="addQuotationTemp()" plain="true"></a>            
        </div>
    </div>

